import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  LoginForm,
  RegisterForm,
  CodeQuery,
  ChangePasswordForm,
  ForgotPasswordForm
} from './types';

/**
 *
 * @param data {LoginForm}
 * @returns
 */
export function loginApi(data: LoginForm): AxiosPromise<string> {
  return request({
    url: 'api/v1/login',
    method: 'post',
    data
  });
}

/**
 * 注销
 */
export function logoutApi() {
  return request({
    url: 'api/v1/logout',
    method: 'get'
  });
}

/**
 * 注册
 *
 * @param data
 */
export function regAdd(data: RegisterForm): AxiosPromise<any> {
  return request({
    url: 'api/v1/register',
    method: 'post',
    data
  });
}

/**
 * 用户发送短信
 *
 * @param data
 */
export function sendCode(data: CodeQuery): AxiosPromise<any> {
  return request({
    url: 'api/v1/sms',
    method: 'post',
    data
  });
}

/**
 * 获取图片验证码
 */
export function getCaptcha(): AxiosPromise<any> {
  return request({
    url: 'api/v1/captchas',
    method: 'get'
  });
}

/**
 * 修改密码
 *
 * @param data
 */
export function changePassword(data: ChangePasswordForm) {
  return request({
    url: 'api/v1/editpass',
    method: 'put',
    data
  });
}

/**
 * 忘记密码
 *
 * @param data
 */
export function forgotPassword(data: ForgotPasswordForm) {
  return request({
    url: 'api/v1/forgetpass',
    method: 'put',
    data
  });
}
